﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LunwenYun.Infrastructure.Entities.Enum;
using LunwenYun.Infrastructure.Entities.Repository;

namespace LunwenYun.Infrastructure.Entities.Entity
{
    public class Agent : IAccessible<T_Agent, Agent>, ILogicEntity<T_Agent, Agent>
    {
        #region
        public int Id { get; set; }

        public int PeriodicalId { get; set; }

        public string UserName { get; set; }

        public DateTime RecordDate { get; set; }

        public DateTime RefreshDate { get; set; }

        public int Rank { get; set; }
        #endregion

        #region extend
        public User User { get; set; }
        public PaperAgentInfo AgentInfo { get; set; }
        #endregion

        protected override void Covariant(T_Agent model)
        {
            if (model != null)
            {
                this.Id = model.Id;
                this.PeriodicalId = model.PeriodicalId;
                this.RecordDate = model.RecordDate;
                this.RefreshDate = model.RefreshDate;
                this.UserName = model.UserName;
                this.Rank = model.Rank;
            }
        }

        protected override T_Agent Inverter(Agent model)
        {
            return new T_Agent()
            {
                Id = model.Id,
                PeriodicalId = model.PeriodicalId,
                RecordDate = model.RecordDate,
                RefreshDate = model.RefreshDate,
                UserName = model.UserName,
                Rank=model.Rank
            };
        }

        public Agent Set(T_Agent dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        public Agent LoadUser(User user)
        {
            this.User = user;
            return this;
        }
        public Agent LoadUser(T_User t_user)
        {
            this.User = new User().Set(t_user);
            return this;
        }
        public Agent LoadAgentInfo(PaperAgentInfo agentInfo)
        {
            this.AgentInfo = agentInfo;
            return this;
        }
        public Agent LoadAgentInfo(T_PaperAgentInfo t_paperAgentInfo)
        {
            this.AgentInfo = new PaperAgentInfo().Set(t_paperAgentInfo);
            return this;
        }
    }
}
